package org.example.controller.oaa;


import lombok.extern.slf4j.Slf4j;
import org.example.dao.entity.user.UUserSpecial;
import org.example.service.oaa.OaaServiceImpl;
import org.example.dao.commom.Result;
import org.example.dao.commom.ResultCode;
import org.example.dao.dto.oaa.OaaWechatLoginKey;
import org.example.skytool.commom.ParamUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/oaa")
@CrossOrigin
@Slf4j
public class OaaController {

    @Resource
    private OaaServiceImpl oaaService;


    /**
     * 小程序登录 code
     */
    @PostMapping("/login")
    public Result Login(@RequestBody OaaWechatLoginKey loginKey) {
        String code = loginKey.getCode();
        String token = oaaService.login(code);
        return new Result(ResultCode.SUCCESS, token);
    }

    /**
     * 验证token
     */
    @PostMapping("/verify")
    public Result verify(@RequestBody OaaWechatLoginKey loginKey) {
        String token = loginKey.getToken();
        token = oaaService.verify(token);
        return new Result(ResultCode.SUCCESS, token);
    }

    /**
     * 独立创建账号密码登录
     */
    @PostMapping("/specialLogin")
    public Result specialLogin(@RequestBody UUserSpecial uUserSpecial){

        String account = uUserSpecial.getAccount();
        String password = uUserSpecial.getPassword();
        ParamUtil.StringParam(account,password);

        String token = oaaService.loginSpecial(account,password);

        return new Result(ResultCode.SUCCESS,token);
    }


}
